find_package(GCTL REQUIRED)
if(GCTL_FOUND)
    include_directories(${GCTL_INCLUDE_DIR})
endif()

find_package(LibLCG REQUIRED)
if(LibLCG_FOUND)
    include_directories(${LibLCG_INCLUDE_DIR})
endif()

find_package(OpenMP REQUIRED)
if (OpenMP_CXX_FOUND)
    set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()

find_package(CUDA REQUIRED)
if(CUDA_FOUND)
    message(STATUS "CUDA Found.")
    enable_language(CUDA)
    include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
    find_library(CUBLAS_LIBRARY cublas ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
    find_library(CUSPARSE_LIBRARY cusparse ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()

aux_source_directory(. SRC_DIR)
aux_source_directory(../utilities/ UTIL_SRC_DIR)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c++11 -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -O3")
add_executable(mt3d_cuda_dia ${SRC_DIR} ${UTIL_SRC_DIR})
target_link_libraries(mt3d_cuda_dia PUBLIC ${GCTL_LIB})
target_link_libraries(mt3d_cuda_dia PUBLIC ${LibLCG_LIB})
target_link_libraries(mt3d_cuda_dia PUBLIC OpenMP::OpenMP_CXX)
target_link_libraries(mt3d_cuda_dia PUBLIC ${CUBLAS_LIBRARY})
target_link_libraries(mt3d_cuda_dia PUBLIC ${CUSPARSE_LIBRARY})